<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\modules\home\models\BooklistSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '漫画列表';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="booklist-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('Create', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\ActionColumn'],

            [
                'attribute' => 'id',
                'value' => 'id',
                'headerOptions' => ['width' => '50'],
            ],
            'backend_title',
            [
                'format' => 'raw',
                'attribute' => 'cid',
                'value' => function($model) {
                    $m = \common\components\Tools::getCateInfo($model->cid);
                    return $m->title;
                },
            ],
            [
                'format' => 'raw',
                'attribute' => 'parent_id',
                'value' => function($model) {
                   if($model->parent_id == 0){
                       return '顶级目录';
                   }else{
                       return $model->parent_id;
                   }
                },
            ],
            [
                'format' => 'raw',
                'attribute' => 'type',
                'value' => function($model) {
                    if($model->type == 1){
                        return '<span class="btn btn-xs btn-primary">单行本</span>';
                    }else{
                        return '<span class="btn btn-xs btn-primary">多行本</span>';
                    }
                },
                'filter' => ['1' => '单行本', '2' => '多行本'],
            ],
            'number',
            //'front_title',

            //'thumb_img',
            //'cont_num',
            //'click_num',
            //'zan_num',
            //'intro',
            //'is_recommend',
            //'is_hot',
            //'is_over',
            //'is_advert',
            [
                'format' => 'raw',
                'attribute' => 'is_free',
                'value' => function($model) {
                    if($model->is_free == 1){
                        return '<span class="btn btn-xs btn-info">vip</span>';
                    }else{
                        return '<span class="btn btn-xs btn-primary">免费</span>';
                    }
                },
                'filter' => ['1' => 'vip', '0' => '免费'],
            ],
            [
                'format' => 'raw',
                'attribute' => 'is_over',
                'value' => function($model) {
                    if($model->parent_id != 0){
                        return '';
                    }else{
                        if($model->is_over == 1){
                            return '<span class="btn btn-xs btn-success">完结</span>';
                        }else{
                            return '<span class="btn btn-xs btn-primary">更新中</span>';
                        }
                    }
                },
                'filter' => ['1' => 'vip', '0' => '免费'],
            ],
            //'mark',
            //'remark',
            //'date',
            //'status',
            //'create_at',


        ],
    ]); ?>
</div>
